home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / gopher / Unix / GopherTools / gofinger.pl.Z / gofinger.pl
Encoding:
Text File  |  1994-08-10  |  5.1 KB  |  167 lines

  1. Article 1981 of comp.infosystems.gopher:
  2. Xref: feenix.metronet.com comp.infosystems.gopher:1981
  3. Newsgroups: comp.infosystems.gopher
  4. Path: feenix.metronet.com!news.ecn.bgu.edu!mp.cs.niu.edu!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!uunet!utcsri!newsflash.concordia.ca!mizar.cc.umanitoba.ca!silver.cs.umanitoba.ca!sbalneav
  5. From: sbalneav@silver.cs.umanitoba.ca (Scott Balneaves)
  6. Subject: Fingering under gopher - gophinger
  7. Message-ID: <sbalneav.734818086@silver.cs.umanitoba.ca>
  8. Summary: a free program to do fingering in gopher
  9. Keywords: gophinger finger gopher
  10. Sender: news@ccu.umanitoba.ca
  11. Nntp-Posting-Host: silver.cs.umanitoba.ca
  12. Organization: University of Manitoba, Winnipeg, Canada
  13. Date: Wed, 14 Apr 1993 20:08:06 GMT
  14. Lines: 149
  15.  
  16. A couple of weeks ago I saw someone who wanted to be able to do a "finger"
  17. under a gopher server.  To this person (whose name escapes me) and to
  18. anyone else that ever wanted to finger people via a gopher, this bud's
  19. for you...
  20.  
  21. I hacked this together in about 2 or 3 hours, so I cannot guarentee
  22. that it's bulletproof.  But, it does seem to work.  If you use it, send
  23. me some mail -- I'd love to see it in action! :-)
  24.  
  25. It requires that you have perl, which you can get from many places.  Instructions
  26. for use are at the top of the program.  Go nuts.
  27.  
  28. Scott
  29.  
  30. ------------CUT HERE--------------------
  31. #!/usr/local/bin/perl
  32. #############################################################################
  33. # Copyright Notice
  34. #############################################################################
  35. # gophinger.perl - Scott L. Balneaves
  36. #
  37. # "I see I've foiled your plans for world dominiation again,
  38. #  Mr. Goldfinger"
  39. #
  40. # Copy it, mangle it, use it, do whatever.  Just leave my name at the top.
  41. # If it don't do something you want it to do, just gimme an e-mail at
  42. # sbalneav@silver.cs.umanitoba.ca
  43. # and I'll see what I can do for 'ya.
  44. #############################################################################
  45. #
  46. # This program uses inetd to get started, so..  you'll need a line in
  47. # your inetd.conf something like the following:
  48. #
  49. # gophinger stream tcp nowait tcp /usr/local/bin/gophinger.perl gophinger
  50. #
  51. # and a line in your /etc/services file something like:
  52. #
  53. # gophinger    71/tcp
  54. #
  55. # in your .Links file, try something to the effect of:
  56. #
  57. # Type=1
  58. # Name=Gophinger finger service
  59. # Host=yourhost.what.ever.that.is
  60. # Port=71
  61. # Path=+
  62. #
  63. # I've structured it so that you can get the list of names in whatever
  64. # way you want.  Gophinger expects to use an /etc/passwd like file.
  65. # You can either use /etc/passwd, or use a modified version of the file.
  66. # for instance, you can create a file like:
  67. # sbalneav@silver.cs.umanitoba.ca::::Scott L. Balneaves::
  68. # sbalneav@ccu.Umanitoba.ca::::Scott L. Balneaves::
  69. #
  70. # as a test, and have gophinger go after that.  That way you can finger
  71. # people on different hosts (internet coke machines, etc :-)
  72. #
  73. # You can also use YP (or NIS if you like) to get the info, pass it
  74. # through a filter that removes certain names, etc.  Whatever you like,
  75. # so long as the output looks like a passwd entry, you'll be fine.
  76. #
  77. # At any rate, $command is the command to use to get the passwd-like file
  78. # into gophinger. I've included a couple, commented out, and one which
  79. # is guarenteed to work :-) (note the trailing pipe symbol at the end of
  80. # the command string)
  81. #
  82. # This program was a quick hack, so don't expect perfection.
  83. #
  84. #############################################################################
  85. #$command = "cat /usr/local/etc/gophinger.passwd |";
  86. #$command = "ypcat passwd | sort |";
  87. $command = "cat /etc/passwd | sort |";
  88.  
  89. $defaultport=71;            # our default port is 71
  90.  
  91. #
  92. # Get the port number from the services file
  93. #
  94. ($name, $aliases, $port) = getservbyname('g2fd','tcp');
  95. $port=$defaultport unless $port;
  96.  
  97. #
  98. # Get our full host name
  99. #
  100. chop($host = `hostname`);
  101. ($host, $aliases, $type, $len, $thisaddr) = gethostbyname($host);
  102.  
  103. #
  104. # Receive our request and hack off the naughty bits :-)
  105. #
  106.  
  107. $line=<STDIN>;
  108. chop $line;        # ouch
  109. chop $line;        # ouch
  110. $line="1" unless $line;
  111.  
  112. #
  113. # did we get a request for a listing(1)? or a request to finger (0)?
  114. #
  115.  
  116. ($type,$name)= split('/',$line);
  117.  
  118. if (! $name) {
  119.   $type="1";
  120. }
  121.  
  122. #
  123. # OK, we got a request to list. Open our pipe, and start squakin'
  124. #
  125. if ($type eq '1') {
  126.     open(PASSWD, $command) || die;
  127.  
  128.     while (<PASSWD>) {
  129.     chop;
  130.     ($login,$passwd,$uid,$gid,$gcos,$home,$home,$shell) = split(/:/);
  131.  
  132.     $putout="0$login  [$gcos]\t0/$login\t$host\t$port\r\n";
  133.     print($putout);
  134.     }
  135.     close (PASSWD);
  136.  
  137.     $putout=".\r\n";
  138.     print($putout);
  139.  
  140. } else {
  141.  
  142. #
  143. # We got a request to finger.  Pipe that and spray the output
  144. #
  145.     open(FINGER, "finger $name |") || die;
  146.  
  147.     while (<FINGER>) {
  148.           chop;
  149.           print "$_\r\n";
  150.         }
  151.  
  152.     close (FINGER);
  153.     $putout=".\r\n";
  154.     print($putout);
  155. }
  156. ------------CUT HERE--------------------
  157.  
  158. -- 
  159. Scott L. Balneaves                           |  sbalneav@silver.cs.umanitoba.ca
  160. "No tears to cry, no feelings left...        |  Weird answers            $1.00
  161.  This species has amused itself to death."   |  Correct, weird answers   $1.50
  162.        - Roger Waters                        |  Crackpot theories         FREE
  163.  
  164.  
  165.